package com.crazyread.dao;

import com.crazyread.model.domain.Book;
import com.crazyread.model.domain.Statistic;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StatisticMapper {
    //通过书籍id查询统计数据
    @Select("select * from statistic where book_id=#{bookId}")
    public Statistic selectStatisticByBid(Integer bookId);
    //新增书籍对应的统计信息
    @Insert("INSERT INTO statistic(book_id,hit,comment_num) values (#{id},0,0)")
    public void addStatistic(Book book);
    //通过文章id更新点击量
    @Update("UPDATE statistic SET hit=#{hit} where book_id =#{bookId} ")
    public void updateBookHitsWithId(Statistic statistic);
    //通过文章id更新评论量
    @Update("update statistic set comment_num=#{commentNum} where book_id=#{bookId}")
    public void updateBookComNum(Statistic statistic);
    //统计书籍的点击量
    @Select("SELECT SUM(hit) FROM statistic")
    public Integer getTotalHit();
    //统计书籍的评论总数量
    @Select("Select SUM(comment_num) FROM statistic where book_id=#{bookId}")
    public Integer getTotalCommNum(int bookId);
    //根据书籍id删除统计数据
    @Delete("DELETE FROM statistic WHERE book_id=#{aid}")
    public void deleteStatisticWithId(int aid);

    public List<Statistic> selectStatistic();
}
